﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace RobotView
{
    public delegate void SwitchChange(object sender, EventArgs e); 
    public partial class Switch : UserControl
    {
        public event SwitchChange SwitchChanged;
        //True = On, false = off
        private bool state;
        
        public bool State
        {
            get { return this.state;  }
            set { this.setState(value); }
        }

        public Switch()
        {
            InitializeComponent();
            this.setState(false);
            this.picBoxSwitch.Click += new EventHandler(picBoxSwitch_Click);
        }

        private void onSwitchChanged()
        {
            SwitchChanged(this, new EventArgs());
        }

        //Event weitergabe weil nur die PictureBox der Klasse Switch das Event erhält
        private void picBoxSwitch_Click(object sender, EventArgs e)
        {
            this.onSwitchChanged();
        }


        //Sets the state an changes the pic
        private void setState(bool p)
        {
            this.state = p;
            if (this.state == true)
            {
                this.picBoxSwitch.Image = Resource1.SWITCH_ON;
            }
            else
            {
                this.picBoxSwitch.Image = Resource1.SWITCH_OFF;
            }
        }
    }
}
//public delegate void SwitchChange(object sender, SwitchEventArgs e); 
//public event SwitchChange SwitchChanged;
/*public class SwitchEventArgs : EventArgs
{
    private int switchNumber;

    public int SwitchNumber
    {
        get { return this.switchNumber; }
    }

    //Index determines which lamp to change
    public SwitchEventArgs(int index)
    {
        this.switchNumber = index;
    }
}*/
